package com.nsu.konus.control.jobs;

import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;

import com.nsu.konus.control.Activator;
import com.nsu.konus.control.ControlManager;

public class RunKonusJob extends Job {
	
	private String solverPath;
	private String dataPath;

	public RunKonusJob(String solverPath, String dataPath) {
		super("Run konus");
		this.setPriority(Job.LONG);
		this.setRule(ResourcesPlugin.getWorkspace().getRoot());

		this.solverPath = solverPath;
		this.dataPath = dataPath;
	}

	protected IStatus run(IProgressMonitor monitor) {
		try {
			ControlManager.getInstance().runSolver(solverPath, dataPath);
		}
		catch(Exception ex) {
			return new Status(Status.ERROR, Activator.PLUGIN_ID, 1, 
					ex.getMessage(), ex);
		}
		return Status.OK_STATUS;
	}
}
